#!/user/bin/env python
# -*- coding: utf-8 -*-
''' 
Author: Sjy
LastEditTime: 2024-08-27 14:27:30
Description: qss 配置管理文件  将qss分文件管理更易于维护
'''

__all__= []


import os
import traceback
from PyQt5 import QtCore, QtGui, QtWidgets

try:
    from .util_file import get_file_extesion, get_file_name
except:
    from util_file import get_file_extesion, get_file_name


global _STYLES
_STYLES = {}

def init():
    global _STYLES
    for root, dirs, files in os.walk("styles"):
        for file in files:
            fileExt = get_file_extesion(file)
            filename = get_file_name(file)
            if fileExt == ".qss":
                try:
                    with open(os.path.join(root, file), "r") as f:
                        _STYLES[filename] = f.read()
                except Exception as e:
                    print(e)
    
def set_qss_to_obj(file_path, obj):
    try:
        if file_path in _STYLES:
            obj.setStyleSheet(_STYLES[file_path])
        else:
            with open(file_path, "r") as f:
                obj.setStyleSheet(f.read())
    except:
        print("Error: set_qss_to_obj", file_path, obj)
        traceback.print_exc()


##  ============窗体测试程序 ================================
if  __name__ == "__main__":        ##用于当前窗体测试
    pass
